package com.gy.smart.life.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.gy.smart.R;
import com.gy.smart.util.ListViewItemListener;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;

/**
 * Created by 高岳 on 2017/1/9.
 * Describe:
 */
public class ADAdapter  extends PagerAdapter {

    private Context context;
    private ArrayList<String> list;
    public ListViewItemListener listener;

    public ADAdapter(Context context, ArrayList<String> list) {
        this.context = context;
        this.list = list;
    }

    public void setListener(ListViewItemListener listener){
        this.listener = listener;
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        // TODO Auto-generated method stub
        return arg0 == arg1;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        //		return list.size();
        return Integer.MAX_VALUE;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
		/*
		 * if (list.size() > 0) { if(null != mViewList.get(position))
		 * container.removeView(mViewList.get(position)); }
		 */
    }

    @Override
    public int getItemPosition(Object object) {
        return super.getItemPosition(object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        View view = View.inflate(context, R.layout.activity_main_ad_item, null);
        ImageView imageView = (ImageView) view.findViewById(R.id.ad_image);
        ImageLoader.getInstance().displayImage(list.get(position % list.size()),imageView);
        container.addView(view, 0);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener != null){
                    listener.doPassActionListener(null,0,position % list.size(),"");
                }
            }
        });
        return view;
    }

}
